﻿using ControlzEx;
using LoveNote.Core.Helpers;
using LoveNote.Database.Entities;
using LoveNote.Database.Helpers;
using MahApps.Metro.IconPacks;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using TookKit.Mvvm.Attributes;
using TookKit.Mvvm.Bindings;
using TookKit.Mvvm.Enums;

namespace LoveNote.Application.Picture.ViewModels
{
    [DependencyInjection(Lifetime.Singleton)]

    internal class PreviewViewModel : ObservableObject
    {
        private PictureEntity picture;
        public PictureEntity Picture
        {
            get { return picture; }
            set { SetProperty(ref picture, value); }
        }

        private double zoom;
        public double Zoom
        {
            get { return zoom; }
            set { SetProperty(ref zoom, value); }
        }

        public ICommand LoadedCommand { get; }
        public ICommand SavePictureCommand { get; }

        public PreviewViewModel()
        {
            LoadedCommand = new RelayCommand(OnLoadedCommand);
            SavePictureCommand = new RelayCommand(OnSavePictureCommand);
        }

        private void OnLoadedCommand()
        {
            
        }

        private void OnSavePictureCommand()
        {
            DateTime now= DateTime.Now;
            string defaultName = $"picture{now.Year}{now.Month}{now.Day}{now.Hour}{now.Minute}{now.Second}";
            if (FileHelper.SaveFileDialog("保存图像", "png Files|*.png", ".png", defaultName, out string fullname))
            {
                var image = ImageHelper.GetBitmapImage(Picture.Content);
                ImageHelper.SaveBitmapImageIntoFile(image, fullname);               
                //PopupBox.Show("图像保存成功");
            }
        }
    }
}
